/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package solitaireofdoom.solitaire;

/**
 * The Card class is used to keep information about a single card, but it contains static information such as the letters for the various suits and the height and width of each card.
 * 
 * @author Administrator
 */
public class Card {

    private char suit;
    private int rank;
    private boolean facing; // True == up, False == down

    public static final char[] Suits;
    public static final int CardWidth;
    public static final int CardHeight;
    public static final int DummyAceCards;
    public static final int DummyCard;

    static {
        Suits = new char[] {
            'H',
            'S',
            'D',
            'C'
        };
        CardWidth = 79;
        CardHeight = 123;
        DummyAceCards = 999;
        DummyCard = 998;
    }
    
    public Card(char suit, int rank) throws CardException 
    {
            this(suit, rank, false);
    }

    public Card(char suit, int rank, boolean facing) throws CardException
    {
        boolean isLegalSuit = false;
        for (int i = 0; i < Suits.length; i++)
        {
            isLegalSuit = isLegalSuit || Suits[i] == suit;
        }
        if ((rank < 14 || rank == 999 || rank == 998) && isLegalSuit)
        {
            this.suit = suit;
            this.rank = rank;
            this.facing = facing;
        }
        else
            throw new CardException("Unknown suit or rank, S:" + suit + ",R:" + rank);
    }

    /**
     * Gets the suit of this card
     * @return the suit of this card
     */
    public char getSuit()
    {
        return this.suit;
    }

    /**
     * sets the suit of this card
     * @param suit the new suit of this card
     * @return the suit of this card after change
     */
    public char setSuit(char suit)
    {
        boolean isLegalSuit = false;
        for (int i = 0; i < Suits.length; i++)
        {
            isLegalSuit = isLegalSuit || Suits[i] == suit;
        }
        if (isLegalSuit)
            this.suit = suit;

        return this.suit;
    }

    /**
     * Gets the rank of this card
     * @return the rank of this card
     */
    public int getRank()
    {
        return this.rank;
    }

    /**
     * Sets the rank of this card
     * @param rank the new rank of this card
     * @return the rank of this card after change
     */
    public int setRank(int rank)
    {
        if (rank < 14)
            this.rank = rank;

        return this.rank;
    }

   /**
    * @return <tt>true</tt> facing up.
    * <tt>false</tt> facing down.
    */
    public boolean getFacing()
    {
        return this.facing;
    }

    /**
     * @param facing <tt>true</tt> facing up, <tt>false</tt> facing down.
     */
    public boolean setFacing(boolean facing)
    {
        this.facing = facing;

        return this.facing;
    }

    /**
     * Returns a string representation of this card
     */
    public String toString()
    {
        return this.getSuit() + "-" + this.getRank();
    }
}
